package com.bonc.insight.controller;

import com.bonc.insight.entity.TRefreshToken;
import com.bonc.insight.service.impl.TRefreshTokenServiceImpl;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bonc.vo.ResultVo;
import java.util.List;

/**
 * <p>
 *   前端控制器
 * </p>
 *
 * @author bonc
 * @since 2022-01-14
 */
@RestController
@RequestMapping("/insight/trefreshtoken")
public class TRefreshTokenController {

   @Resource
   private TRefreshTokenServiceImpl trefreshtokenService;

    /**
      * 单条保存or更新
      * @param trefreshtoken
      * @return
      */
    @PostMapping("/saveOrUpdate")
    public ResultVo saveOrUpdate(@RequestBody TRefreshToken trefreshtoken){
        boolean state = trefreshtokenService.saveOrUpdate(trefreshtoken);
        if(!state){
            return ResultVo.getFail();
        }
        return ResultVo.getSuccess();
    }

    /**
     * 批量保存or批量更新
     * @param trefreshtokenList
     * @param batchSize
     * @return
     */
    @PostMapping("/saveOrUpdateBatch")
    public ResultVo saveOrUpdateBatch(@RequestParam("trefreshtokenList") List< TRefreshToken> trefreshtokenList,int batchSize){
        boolean state = trefreshtokenService.saveOrUpdateBatch(trefreshtokenList,batchSize);
        if(!state){
            return ResultVo.getFail();
        }
        return ResultVo.getSuccess();
    }

    /**
    * 通过id删除
    * @param id
    * @return
    */
    @PostMapping("/removeById")
    public ResultVo removeById(@RequestParam("id") String id) {
        boolean state = trefreshtokenService.removeById(id);
        if(!state){
            return ResultVo.getFail();
        }
        return ResultVo.getSuccess();
    }

    /**
    * 通过id集合删除
    * @param ids
    * @return
    */
    @PostMapping("/removeByIds")
    public ResultVo removeByIds(@RequestParam("ids") List<String> ids) {
        boolean state = trefreshtokenService.removeByIds(ids);
        if(!state){
            return ResultVo.getFail();
        }
        return ResultVo.getSuccess();
    }

    /**
     * 通过id查询
     * @param id
     * @return
     */
    @PostMapping("/getById")
    public ResultVo<TRefreshToken> getById(@RequestParam("id") String id) {
        return ResultVo.getSuccess(trefreshtokenService.getById(id));
    }

    /**
     * 分页条件查询
     * @param trefreshtoken
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public ResultVo<IPage<TRefreshToken>> getPageList(@RequestBody TRefreshToken trefreshtoken,
                                                        @RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                                        @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        return ResultVo.getSuccess(trefreshtokenService.getTRefreshTokenList(pageNum,pageSize,trefreshtoken));
    }

}
